home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / mail / mh / contrib / jpeek / mhall < prev    next >
Text File  |  1992-08-09  |  3KB  |  108 lines

  1. #! /bin/csh -f
  2. #    $Header: mhall.csh,v 1.2 88/12/09 05:26:54 jerryp Exp $
  3. #
  4. ###    mhall - apply a command to some or all of your MH folders.
  5. ###    Usage: mhall [-r] [-n] [-c command] [command-arg...] [+folder...]
  6. #
  7. #    Date: 8 Dec 88 17:27:14 GMT
  8. #    From: Wayne Mesard <bbn.com!mesard@bbn.com>
  9. #    Organization: Bolt Beranek and Newman Inc., Cambridge MA
  10. #    Subject: MHALL - do something to a lot of folders
  11. #    Sender: mh-users-request@uci.edu
  12. ##    
  13. ##    Here's a little script I whipped up this morning.  It repeatedly applies
  14. ##    a command (with optional arguments) to a bunch of folders.  I wrote it
  15. ##    because I'm forever forgetting where I refile'd a message to the night
  16. ##    before, and wanted a quick n dirty way to look for it.
  17. ##    
  18. ##    The default command and argument are "scan" and "last".  The default
  19. ##    folders are all your top-level folders.
  20. ##    
  21. ##    When folders are explicitly named subfolders will also be processed.
  22. ##    The -n switch prevents this recursion.  Conversly, when no folders are
  23. ##    given, the top-level ones are used.  The -r switch will cause subfolders
  24. ##    to be processed as well.  To apply a command other than "scan" use the
  25. ##    -c switch.
  26. ##    
  27. ##    Examples:
  28. ##    ---------
  29. ##    mhall first:2 5 +unix +inbox
  30. ##       Will "scan" the first two messages and message number 5 in +unix,
  31. ##       +inbox and any subfolders.
  32. ##    
  33. ##    mhall -c show
  34. ##       Show the current message of each top-level folder.
  35. ##    
  36. ##    mhall -c folder -pack -r
  37. ##       Invoke "folder" with the -pack option on every folder and subfolder.
  38. ##    
  39. ##    Disclaimer: This is not elegant.
  40.  
  41. #      mhall - apply a command to some or all of your MH folders.
  42. #      Copyright (c) 1988 Wayne Mesard
  43. #
  44. #      This is free software.  It may be reproduced, retransmitted,
  45. #      redistributed and otherwise propogated at will, provided that
  46. #      this notice remains intact and in place.
  47. #
  48. #      Please direct bug reports, code enhancements and comments
  49. #      to mesard@BBN.COM.
  50.  
  51. set mh = /usr/local/mh    # WHERE MH COMMANDS LIVE
  52. set tfolders
  53. set args
  54. set cmd
  55. set recurse
  56. set curfolder = `$mh/folder -fast`
  57.  
  58. while ( X$1 != X )
  59.   switch ($1)
  60.     case -help:
  61.       echo "syntax: `basename $0` [-r] [-n] [-c command] [command-arg...] [+folder...]"
  62.       exit 0
  63.     case -c:
  64.       set cmd = "$2"
  65.       shift
  66.       breaksw
  67.     case -r:
  68.       set recurse = "-recurse"
  69.       breaksw
  70.     case -n:
  71.       set recurse = "-norecurse"
  72.       breaksw
  73.     case +*:
  74.       set tfolders = "$tfolders $1"
  75.       breaksw
  76.     default:
  77.       set args = "$args $1"
  78.       breaksw
  79.   endsw
  80.   shift
  81. end
  82.  
  83. if ("$tfolders" == "") then
  84.   set folders = `$mh/folders $recurse -fast`
  85. else
  86.   set folders
  87.   foreach folder ($tfolders)
  88.     set folders = "$folders `$mh/folder $folder -recurse $recurse -fast`"
  89.   end
  90. endif
  91.  
  92. if ("$cmd" == "") then
  93.   set cmd = "$mh/scan"
  94.   if ("$args" == "") set args = "last"
  95. endif
  96.  
  97. onintr CLEANUP
  98.  
  99. foreach folder ($folders)
  100.   echo :${folder}:
  101.   # DON'T USE $mh/ HERE; $cmd MIGHT BE IN ANOTHER DIRECTORY:
  102.   $cmd +$folder $args
  103. end
  104.  
  105. CLEANUP:
  106. $mh/folder +$curfolder >/dev/null
  107. exit 0
  108.